/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.swta.components.unit;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.model.CompoundPropertyModel;

/**
 *
 * @author Jan Korreck
 */
public abstract class UnitForm extends Form {


    private boolean editMode = false;
    private String unitName = "";


    private RequiredTextField nameField = new RequiredTextField("name");
//    TextField maxID = new TextField("maxCatID");

    public UnitForm(String id) {
        super(id);
        Unit newUnit = new Unit();
        this.setModel(new CompoundPropertyModel(newUnit));
        this.add(nameField);
    }

    public void setEdit(boolean edit) {
        this.editMode = edit;
    }

    public void setCatName(String catName) {
        this.unitName = catName;
    }

    @Override
    protected void onSubmit() {
        
        Unit unitModel = (Unit) getModelObject();
        if (this.editMode) {
            UnitManager.getInstance().removeUnit(unitName);
        }
        UnitManager.getInstance().addUnit(unitModel);

        this.setResponsePage(Units.class);
    }
    
    public abstract void submitClicked();

}
